package com.zhiban.project.controller;

import java.util.HashMap;

import com.ccms.dinamica.SecurityFilter;

import dinamica.Db;
import dinamica.GenericTableManager;
import dinamica.Recordset;
import dinamica.audit.AuditableTransaction;

/**
 * Clase que ejecuta un recordset despues que ha
 * se ha realizado la transaccion este recordset
 * es publicado<br><br>
 * Fecha de creacion: 2010-08-06<br>
 * Fecha de actualizacion: 2010-08-06<br>
 * @author Martin Cordova y Asociados C.A
 */
public class AuthInsertTransaction  extends GenericTableManager {

	@Override
	public int service(Recordset inputParams) throws Throwable {
		
		int rc = super.service(inputParams);
		loadProtectedResources();
		return rc;
	}

	void loadProtectedResources() throws Throwable {
		String _appAlias="ccc";
		HashMap<String, String[]> protectedRes = new HashMap<String, String[]>();
		try {

			String sql = "";

			Db db = getDb();
			sql = "select service_id, path"
					+ " from s_service s, s_application a"
					+ " where s.app_id = a.app_id" + " and a.app_alias = '"
					+ _appAlias + "'";
			Recordset rs = db.get(sql);
			String query = "select role_id from service_role_view sr where sr.service_id = ";
			while (rs.next()) {
				sql = query + rs.getString("service_id");
				Recordset rs2 = db.get(sql);
				String roles[] = new String[rs2.getRecordCount()];
				int i = 0;
				while (rs2.next()) {
					roles[i] = rs2.getString("role_id");
					i++;
				}
				protectedRes.put(rs.getString("path"), roles);
			}
			SecurityFilter.protectedRes=protectedRes;
		} catch (Throwable error) {
			throw error;
		} finally {
		}

	}
}
